package bawei.com.adapter;


import android.content.Context;

import android.support.v7.widget.RecyclerView;



import android.view.LayoutInflater;

import android.view.View;
import android.view.ViewGroup;



import android.widget.Button;
import android.widget.ImageView;


import android.widget.TextView;



import com.bumptech.glide.Glide;

import java.util.List;


import bawei.com.bilibili.R;
import bawei.com.model.bean.GameCenterBean;

/**
 * 类描述:
 * 作者：cwm
 * 时间:2017/3/21 14:46
 * 邮箱:18310832074@163.com
 */

public class GameCentreAdapter extends RecyclerView.Adapter{

    private Context context;
    private List<GameCenterBean.ItemsBean> items;


    public GameCentreAdapter(Context context, List<GameCenterBean.ItemsBean> items) {
        this.context = context;
        this.items = items;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new GameCentreViewHolder(LayoutInflater.from(context).inflate(R.layout.item_game_center,parent,false));
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {

        GameCentreViewHolder viewHolder= (GameCentreViewHolder) holder;
        Glide.with(context)
                .load(items.get(position).getCover())
                .into(viewHolder.imageView);
        viewHolder.textView1.setText(items.get(position).getTitle());
        viewHolder.textView2.setText(items.get(position).getSummary());
        viewHolder.button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onClikLiter.recycOnClikLiter(position);
            }
        });
    }
    @Override
    public int getItemCount() {
        return items.size();
    }

    class GameCentreViewHolder extends RecyclerView.ViewHolder{

        ImageView imageView;
        TextView textView1,textView2;
        Button button;

        public GameCentreViewHolder(View itemView) {
            super(itemView);
            imageView= (ImageView) itemView.findViewById(R.id.item_img);
            textView1= (TextView) itemView.findViewById(R.id.item_title);
            textView2= (TextView) itemView.findViewById(R.id.item_desc);
            button= (Button) itemView.findViewById(R.id.item_btn);
        }
    }
    private OnClikLiter onClikLiter;

    public void setOnClikLiter(OnClikLiter onClikLiter){

        this.onClikLiter=onClikLiter;

    }
    public interface OnClikLiter{

        void recycOnClikLiter(int p);


    }
}
